# import argparse
# import os
# import sys
# from pathlib import Path
#
# import torch
# import torch.backends.cudnn as cudnn
#
# from models.common import DetectMultiBackend
# from utils.datasets import IMG_FORMATS, VID_FORMATS, LoadImages, LoadStreams
# from utils.general import (LOGGER, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2,
#                            increment_path, non_max_suppression, print_args, scale_coords, strip_optimizer, xyxy2xywh)
# from utils.plots import Annotator, colors, save_one_box
# from utils.torch_utils import select_device, time_sync
#
# FILE = Path(__file__).resolve()
# ROOT = FILE.parents[0]  # YOLOv5 root directory
# if str(ROOT) not in sys.path:
#     sys.path.append(str(ROOT))  # add ROOT to PATH
# ROOT = Path(os.path.relpath(ROOT, Path.cwd()))  # relative
#
#
# def generate_random_str(randomlength=16):
#     """
#     生成一个指定长度的随机字符串
#     """
#     random_str = ''
#     base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789'
#     length = len(base_str) - 1
#     for i in range(randomlength):
#         random_str += base_str[random.randint(0, length)]
#     return random_str
#
#
# def predict(im,  #
#             weights=ROOT / 'best.pt',  # 图片路径
#             augment=False,  # augmented inference
#             imgsz=(640, 640),  # inference size (height, width)
#             dnn=False,  # use OpenCV DNN for ONNX inference
#             conf_thres=0.25,  # confidence threshold
#             iou_thres=0.45,  # NMS IOU threshold
#             max_det=1000,  # maximum detections per image
#             classes=None,  # filter by class: --class 0, or --class 0 2 3
#             agnostic_nms=False,  # class-agnostic NMS
#             project=ROOT / 'runs/detect',  # 保存的路径
#             name='exp',  # save results to project/name
#             exist_ok=False,  # existing project/name ok, do not increment
#             data=ROOT / 'data/coco128.yaml',  # dataset.yaml path
#             half=False,  # use FP16 half-precision inference 使用 FP16 半精度推理
#             ):
#     device = torch.device("cpu")  # 设置cpu 。指定cpu 运行
#
#     # 创建模型
#     model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half)
#
#     # 校验图片大小
#     stride, names, pt = model.stride, model.names, model.pt
#     imgsz = check_img_size(imgsz, s=stride)  # check image size
#
#     bs = 1  # batch_size
#
#     pred = model(im, augment=False, visualize=True)
#
#     pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms, max_det=max_det)
#
#     # 接下来应该保存图片
#     for i, det in enumerate(pred):  # per image
#         imc = im0.copy() if save_crop else im0  # for save_crop
#
#         annotator = Annotator(im0, line_width=line_thickness, example=str(names))
#
#
